package top.datacluster.basic.test;

import java.util.HashMap;
import java.util.Map;

public class DeepCopy {

    public static Map<String, Node> nodeMap = new HashMap<String, Node>();


    public Node deep(Node root){
        return root.copy();

    }

    public static class Node{
        private Object data;

        private Node node;

        private Node random;

        public Object getData() {
            return data;
        }

        public void setData(Object data) {
            this.data = data;
        }

        public Node getNode() {
            return node;
        }

        public void setNode(Node node) {
            this.node = node;
        }

        public Node getRandom() {
            return random;
        }

        public void setRandom(Node random) {
            this.random = random;
        }

        public Node copy(){
            if (nodeMap.containsKey(this.hashCode())){
                return nodeMap.get(this.hashCode());
            }else{
                Node deepnode = new Node();
                deepnode.setData(data);
                deepnode.setRandom(random.copy());
                deepnode.setNode(node.copy());
                return deepnode;
            }


        }


    }
}
